From f81967e2f7ac2205c468daec264ae535d64eb42d Mon Sep 17 00:00:00 2001 From: "kraxel@bytesex.org[kaf24]" Date: Fri, 29 Apr 2005 12:54:16 +0000 Subject: [PATCH] bitkeeper revision 1.1389.1.13 (42722e78tJ9dMvMOlJBiS68RNPTvfw) [PATCH] [patch] pgtable.c cleanups Hi guys, The new mm_(un)pin stuff is certainly a nice optimization. But can we take care a bit more about coding style issues and write code not *that* hackish please? Casts, code duplication, "unsigned long" for page table entries *again*. And a few more variables also make the code more readable (and gcc should be clever enougth that this isn't a performance hit). We want to have that merged some day in mainline, don't we? The patch below cleans up the pin/unpin code in pgtable.c I've created two helper functions to factor out common code, the page table walk is basically the same for both pin and unpin, it's just different page flags. Also fixed up the walk code to correcly walk through all 4 levels linux has, so it works correctly for the PAE case. For x86_64 it should work fine as well (untested though). please apply, Gerd --- BitKeeper/etc/logging_ok | 1 + .../arch/xen/i386/mm/pgtable.c | 77 +++++++++++-------- 2 files changed, 46 insertions(+), 32 deletions(-) diff --git a/BitKeeper/etc/logging_ok b/BitKeeper/etc/logging_ok index 943f7d9fbd..d0fc567e14 100644 --- a/BitKeeper/etc/logging_ok +++ b/BitKeeper/etc/logging_ok @@ -56,6 +56,7 @@ kaf24@striker.cl.cam.ac.uk kaf24@viper.(none) katzj@redhat.com kmacy@shemp.lab.netapp.com +kraxel@bytesex.org laudney@eclipse.(none) leendert@watson.ibm.com lynx@idefix.cl.cam.ac.uk diff --git a/linux-2.6.11-xen-sparse/arch/xen/i386/mm/pgtable.c b/linux-2.6.11-xen-sparse/arch/xen/i386/mm/pgtable.c index f71dac0d7d..7a586cab7e 100644 --- a/linux-2.6.11-xen-sparse/arch/xen/i386/mm/pgtable.c +++ b/linux-2.6.11-xen-sparse/arch/xen/i386/mm/pgtable.c @@ -407,30 +407,58 @@ void make_pages_writable(void *va, unsigned int nr) } #endif /* CONFIG_XEN_SHADOW_MODE */ -void mm_pin(struct mm_struct *mm) +static inline void mm_walk_set_prot(void *pt, pgprot_t flags) { - pgd_t *pgd; - struct page *page; - int i; + struct page *page = virt_to_page(pt); + unsigned long pfn = page_to_pfn(page); - spin_lock(&mm->page_table_lock); + if (PageHighMem(page)) + return; + HYPERVISOR_update_va_mapping( + (unsigned long)__va(pfn << PAGE_SHIFT), + pfn_pte(pfn, flags), 0); +} - for ( i = 0, pgd = mm->pgd; i < USER_PTRS_PER_PGD; i++, pgd++ ) - { - if ( *(unsigned long *)pgd == 0 ) - continue; - page = pmd_page(*(pmd_t *)pgd); - if ( !PageHighMem(page) ) - HYPERVISOR_update_va_mapping( - (unsigned long)__va(page_to_pfn(page)<pgd; + for (g = 0; g < USER_PTRS_PER_PGD; g++, pgd++) { + if (pgd_none(*pgd)) + continue; + pud = pud_offset(pgd, 0); + if (PTRS_PER_PUD > 1) /* not folded */ + mm_walk_set_prot(pud,flags); + for (u = 0; u < PTRS_PER_PUD; u++, pud++) { + if (pud_none(*pud)) + continue; + pmd = pmd_offset(pud, 0); + if (PTRS_PER_PMD > 1) /* not folded */ + mm_walk_set_prot(pmd,flags); + for (m = 0; m < PTRS_PER_PMD; m++, pmd++) { + if (pmd_none(*pmd)) + continue; + pte = pte_offset_kernel(pmd,0); + mm_walk_set_prot(pte,flags); + } + } + } +} +void mm_pin(struct mm_struct *mm) +{ + spin_lock(&mm->page_table_lock); + + mm_walk(mm, PAGE_KERNEL_RO); HYPERVISOR_update_va_mapping( (unsigned long)mm->pgd, pfn_pte(virt_to_phys(mm->pgd)>>PAGE_SHIFT, PAGE_KERNEL_RO), 0); xen_pgd_pin(__pa(mm->pgd)); - mm->context.pinned = 1; spin_unlock(&mm->page_table_lock); @@ -438,28 +466,13 @@ void mm_pin(struct mm_struct *mm) void mm_unpin(struct mm_struct *mm) { - pgd_t *pgd; - struct page *page; - int i; - spin_lock(&mm->page_table_lock); xen_pgd_unpin(__pa(mm->pgd)); HYPERVISOR_update_va_mapping( (unsigned long)mm->pgd, pfn_pte(virt_to_phys(mm->pgd)>>PAGE_SHIFT, PAGE_KERNEL), 0); - - for ( i = 0, pgd = mm->pgd; i < USER_PTRS_PER_PGD; i++, pgd++ ) - { - if ( *(unsigned long *)pgd == 0 ) - continue; - page = pmd_page(*(pmd_t *)pgd); - if ( !PageHighMem(page) ) - HYPERVISOR_update_va_mapping( - (unsigned long)__va(page_to_pfn(page)<context.pinned = 0; spin_unlock(&mm->page_table_lock); -- 2.30.2